#include "playMode.h"
#include "playStatus.h"
#include "pauseStatus.h"
#include "titleStatus.h"
#include "gameoverStatus.h"
#include "game.h"


CPlayMode::CPlayMode( CInput *input,CEngine *engine,CDraw *draw,CSound *sound,CGame *game )
	:CMode( input,engine,draw,sound,game ),m_player(NULL),m_font(NULL),m_nScore(0),m_fpBackground(0.0f)
{
	m_statusPlay=new CPlayStatus(this);
	m_statusPause=new CPauseStatus(this);
	m_statusTitle=new CTitleStatus(this);
	m_statusGameover=new CGameoverStatus(this);
	InitWord();
	Title();

}

VOID CPlayMode::InitWord()
{
	D3DXFONT_DESC df;
	ZeroMemory( &df,sizeof(D3DXFONT_DESC));
	df.Height=20;
	df.Width=10;
	df.Weight=10;
	df.MipLevels=D3DX_DEFAULT;
	df.Italic=FALSE;
	df.CharSet=DEFAULT_CHARSET;
	df.OutputPrecision=0;
	df.Quality=0;
	df.PitchAndFamily=0;
	wsprintf(df.FaceName,L"Times New Roman");
	D3DXCreateFontIndirect( m_engine->m_device,&df,&m_font );

	
	ZeroMemory( &df,sizeof(D3DXFONT_DESC));
	df.Height=40;
	df.Width=20;
	df.Weight=10;
	df.MipLevels=D3DX_DEFAULT;
	df.Italic=FALSE;
	df.CharSet=DEFAULT_CHARSET;
	df.OutputPrecision=0;
	df.Quality=0;
	df.PitchAndFamily=0;
	wsprintf(df.FaceName,L"Times New Roman");
	D3DXCreateFontIndirect( m_engine->m_device,&df,&m_bigFont );


}


VOID CPlayMode::Control()
{
	m_status->DisposeInput();
	m_status->DisposeGame();
}

VOID CPlayMode::Draw( DWORD dwNow,DWORD dwFPS )
{
	m_status->Draw();
}

VOID CPlayMode::Pause()
{
	m_status=m_statusPause;
	Sleep(200);
}


VOID CPlayMode::Play()
{
	m_status=m_statusPlay;
}


VOID CPlayMode::Restart()
{
	Play();
	ReleaseEnemy();
	m_statusPlay->Restart();
	m_nScore=0;
}


VOID CPlayMode::Exit()
{
	m_game->Exit();
}


VOID CPlayMode::Title()
{
	m_status=m_statusTitle;
	Sleep(200);
}


VOID CPlayMode::Gameover()
{
	m_status=m_statusGameover;

}


VOID CPlayMode::ReleaseEnemy()
{
	std::list<CObject*>::iterator iter;

	for( iter=m_listEnemy.begin();
		iter!=m_listEnemy.end();
		iter++ )
	{
		delete *iter;
	}
	m_listEnemy.clear();

	for( iter=m_listEnemyBullet.begin();
		iter!=m_listEnemyBullet.end();
		iter++ )
	{
		delete *iter;
	}
	m_listEnemyBullet.clear();

	for( iter=m_listPlayerBullet.begin();
		iter!=m_listPlayerBullet.end();
		iter++ )
	{
		delete *iter;
	}
	m_listPlayerBullet.clear();


}

CPlayMode::~CPlayMode()
{
	
	delete m_statusPause;
	m_statusPause=NULL;

	delete m_statusPlay;
	m_statusPlay=NULL;

	delete m_statusTitle;
	m_statusTitle=NULL;
	
	delete m_player;
	m_player=NULL;

	ReleaseEnemy();

	m_font->Release();
	m_font=NULL;
}